package com.example.ycdyus.dailyfruit.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.example.ycdyus.dailyfruit.R;
import com.example.ycdyus.dailyfruit.adapter.BaikeDetailsVPAdapter;
import com.example.ycdyus.dailyfruit.constant.URLConstant;
import com.example.ycdyus.dailyfruit.fragment.TuijianFragment;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.viewpagerindicator.TabPageIndicator;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;

@EActivity(R.layout.activity_baike_details)
public class BaikeDetailsActivity extends AppCompatActivity {


    @ViewById
    TabPageIndicator baikeDetailsTpi;
    @ViewById
    ViewPager baikeDetailsVp;


    private BaikeDetailsVPAdapter adapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private String[] titles = {"推荐", "健康养生", "小知识", "料理", "趣闻", "媒体报道"};

    @AfterViews
    public void init(){
        fragments.add(new TuijianFragment());
        fragments.add(new TuijianFragment());
        fragments.add(new TuijianFragment());
        fragments.add(new TuijianFragment());
        fragments.add(new TuijianFragment());
        fragments.add(new TuijianFragment());
        adapter = new BaikeDetailsVPAdapter(getSupportFragmentManager(), fragments, titles);
        baikeDetailsVp.setAdapter(adapter);
        baikeDetailsTpi.setViewPager(baikeDetailsVp);
    }
    private void initData() {
        HttpUtils httpUtils =  new HttpUtils();
        httpUtils.send(HttpRequest.HttpMethod.POST, URLConstant.MAIN_BAIKE_DETAILS_POST, getRequestParams(), new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                Log.e("", "");
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
    }

    private RequestParams getRequestParams(){
        RequestParams params = new RequestParams();
        params.addBodyParameter("sign","dc4c5f35f3a79bb0b473225ef53e1e89");
        params.addBodyParameter("limit","20");
        params.addBodyParameter("timestamp","1445516472");
        params.addBodyParameter("sec_id","1");
        params.addBodyParameter("platform","ANDROID");
        params.addBodyParameter("source","app");
        params.addBodyParameter("page","1");
        params.addBodyParameter("connect_id","161c2ae532723d329ee711d284a1b36e");
        params.addBodyParameter("region_id","106092");
        params.addBodyParameter("service","bake.getArticleList");
        params.addBodyParameter("device_id","1b8ba62bf241cee5b8c317d07c0c503e");
        params.addBodyParameter("channel","portal");
        params.addBodyParameter("version","3.0.3");
        return params;
    }

}
